//
//  YFLdetailViewController.m
//  Music
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YFLdetailViewController.h"
#import "YFLmainTableViewCell.h"
#import "NianFeilongModel.h"
#import "Mytools.h"
#import "YFLlittleViewController.h"
@interface YFLdetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView *mainTableView;

@property(nonatomic,strong) NSMutableArray *sourceArray;
@end

@implementation YFLdetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.barStyle = 1;
   self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.sourceArray =[NSMutableArray array];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = self.titleStr;
    self.view.backgroundColor =[UIColor yellowColor];
    
    [self getMoreData];
   
    
    
    
    
    
   }



//创建tableView
-(void)creatMainTableView
{
    
    self.mainTableView =[[UITableView alloc]initWithFrame:CGRectMake(0,0, Screenwidth, Screenheight-49-64) style:(UITableViewStylePlain)];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
    
    
    [self.mainTableView registerClass:[YFLmainTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YFLmainTableViewCell *cell =[self.mainTableView dequeueReusableCellWithIdentifier:@"cell"];
    
   
    NianFeilongModel *Model =[self.sourceArray objectAtIndex:indexPath.row];
    cell.YFLmodel = Model;
    
    //cell.backgroundColor =[UIColor orangeColor];
    return cell;
    
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.sourceArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}



//tableView点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    YFLlittleViewController *littltVC =[[YFLlittleViewController alloc]init];
    NianFeilongModel *Model =[self.sourceArray objectAtIndex:indexPath.row];
    littltVC.nameTitle = Model.name;
    littltVC.photoString = Model.picUrl;
    littltVC.strID = Model.singerId;
    [self.navigationController pushViewController:littltVC animated:YES];
    
    
}



//获取数据
-(void)getMoreData
{
    
    
    NSString *str =[NSString stringWithFormat:@"http://api.dongting.com/song/singer_classify/%ld%@",(long)self.integer,@"?app=ttpod&v=v9.0.2.2016052421&user_id=0&mid=iPhone8%2C1&f=f320&s=s310&imsi=&hid=&splus=9.3.1&active=1&net=2&openudid=a435546e84876b149d2058bd4f519680e815c457&idfa=DB82CD6A-AC09-4AA6-BB95-4D4C536F8E07&utdid=Vu9c0yfFE5kDACwlSAWrz4%2B%2F&alf=(null)&bundle_id=com.ttpod.music&latitude=38.88328450520833&longtitude=121.5445640733507&access_token=(null)&vc=9000200"];
 //   NSLog(@"=======================%@",str);
    
   [MyTools getNetWithUrl:str body:nil header:nil response: LHQJSON success:^(id result) {
       
       NSDictionary *dictionary = (NSDictionary *)result;
       
       
       NSArray *array =[dictionary objectForKey:@"data"][@"singers"];
       
       
     //  NSLog(@"********************%@",array);
       
       for (NSDictionary *dict in array) {
           NianFeilongModel *YFLmodel =[NianFeilongModel new];
           [YFLmodel setValuesForKeysWithDictionary:dict];
           [self.sourceArray addObject:YFLmodel];
       }
       [self creatMainTableView];
       [self.mainTableView reloadData];
       
   } failure:^(NSError *error) {
       
   }];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
